<?php
/* -------------------------------------------------------------------------------------
* 	ID:						$Id: xajax.blog.php 11 2013-09-21 11:43:11Z phone.mueller@googlemail.com $
* 	Letzter Stand:			$Revision: 11 $
* 	zuletzt geaendert von:	$Author: siekiera $
* 	Datum:					$Date: 2013-09-21 11:43:11 +0000 (Sat, 21 Sep 2013) $
*
* 	SEO:mercari by Siekiera Media
* 	http://www.seo-mercari.de
*
* 	Copyright (c) since 2011 SEO:mercari
* --------------------------------------------------------------------------------------
* 	based on:
* 	(c) 2000-2001 The Exchange Project  (earlier name of osCommerce)
* 	(c) 2002-2003 osCommerce - www.oscommerce.com
* 	(c) 2003     nextcommerce - www.nextcommerce.org
* 	(c) 2005     xt:Commerce - www.xt-commerce.com
*
* 	Released under the GNU General Public License
* ----------------------------------------------------------------------------------- */

function blogAction($id, $action, $lng = '') {
	global $db;
	
	$output = '';
	
	$ajax = new xajaxResponse();

	if($action == 'items') {
		$getCatItems = $db->db_query("SELECT 
											name, 
											status, 
											position, 
											item_id 
										FROM 
											".TABLE_BLOG_ITEMS." 
										WHERE 
											categories_id = '".$id."' 
										AND 
											language_id = '". $lng."' 
										ORDER BY 
											position ASC ");
		if($getCatItems->_numOfRows) {
			$output = '<td>&nbsp;</td><td><table width="100%" border="0">';
			$output .= '<tr><td style="border: 1px solid #DADFE0" width="1"><b>Aktion</b></td><td style="border: 1px solid #DADFE0"><b>Titel</b></td><td style="border: 1px solid #DADFE0"><b>Status</b></td><td style="border: 1px solid #DADFE0"><b>Position</b></td></tr>';
			
			while(!$getCatItems->EOF) {
				$output .=  '<tr>';
				$output .=  '	<td style="border: 1px solid #DADFE0" align="center"><a href="blog.php?action=edit_item&cat='.$id.'&item='.$getCatItems->fields['item_id'].'&'.getMenuID('blog').'"><img src="images/icons/edit.gif" alt="Beitrag bearbeiten" title="Beitrag bearbeiten" /></a></td>';
				$output .=  '	<td style="border: 1px solid #DADFE0">'.$getCatItems->fields['name'].'</td>';
				if($getCatItems->fields['status'] == '1')
					$status = 'Offline';
				elseif ($getCatItems->fields['status'] == '2')
					$status = 'Online';
				$output .=  '	<td style="border: 1px solid #DADFE0">'.$status.'</td>';
				$output .=  '	<td style="border: 1px solid #DADFE0">'.$getCatItems->fields['position'].'</td>';
				$output .=  '</tr>';
				$getCatItems->MoveNext();
			}
			$output .= '</table></td><td>&nbsp;</td><td>&nbsp;</td>';
			
		} else
			$output = '<td>&nbsp;</td><td colspan="3"><em>'.NO_BLOG_ENTRIES.'</em></td>';
			
		$ajax->insertAfter('blog_cat_'.$id, 'tr', 'all_items_'.$id);
		$ajax->assign('all_items_'.$id, 'innerHTML', $output);
		$ajax->remove('ajax_overlay');
		
	} elseif ($action == 'com') {
		$com = $db->db_query("SELECT id, name, text, date FROM ".TABLE_BLOG_COMMENT." WHERE blog_id = '".$id."' ORDER BY date ASC ");
		if($com->_numOfRows) {
			$output .= '<td>&nbsp;</td><td colspan="2"><table width="100%" border="0" id="all_comments_'.$id.'">';
			$output .= '<tr><td style="border: 1px solid #DADFE0" width="1"><b>Aktion</b></td><td style="border: 1px solid #DADFE0"><b>Name</b></td><td style="border: 1px solid #DADFE0"><b>Kommentar</b></td><td style="border: 1px solid #DADFE0" align="right"><b>Datum</b></td></tr>';
			while(!$com->EOF) {
				$output .=  '<tr id="com_'.$com->fields['id'].'">';
				$output .=  '	<td style="border: 1px solid #DADFE0; cursor:pointer" align="center" valign="top"><img src="images/icons/balloon--minus.png" alt="" onclick="if(confirm(\'Wollen Sie diesen Komentar wirklich löschen?\'))xajax_blogAction('.$com->fields['id'].',\'del\')" /></td>';
				$output .=  '	<td style="border: 1px solid #DADFE0">'.$com->fields['name'].'</td>';
				$output .=  '	<td style="border: 1px solid #DADFE0">'.$com->fields['text'].'</td>';
				$output .=  '	<td style="border: 1px solid #DADFE0" align="right">'. date_short($com->fields['date']).'</td>';
				$output .=  '</tr>';
				$com->MoveNext();
			}
			$output .= '</table></td><td>&nbsp;</td><td>&nbsp;</td>';

		} else
			$output = '<td>&nbsp;</td><td colspan="4"><em>'.NO_BLOG_COMMENTS.'</em></td>';
			
		$ajax->insertAfter('blog_item_'.$id, 'tr', 'all_comments_'.$id);
		$ajax->assign('all_comments_'.$id, 'innerHTML', $output);
		$ajax->remove('ajax_overlay');
		
	} elseif($action == 'del') {
		$db->db_query("DELETE FROM ".TABLE_BLOG_COMMENT." WHERE id = '".$id."'");
		$ajax->script('$("#com_'.$id.'").fadeOut(500,function(){$(this).remove();})');
	}
	return $ajax;
}

require_once(DIR_WS_INCLUDES.'/xajax/xajax_core/xajax.inc.php');
$xajax = new xajax();

$xajax->registerFunction('blogAction');

$xajax->processRequest();
?>